<template>
	<zui-box>
		<!-- 头部导航 -->
		<zui-navbar title="我的朋友"></zui-navbar>

		<u-gap height="30rpx"></u-gap>
		
		<mescroll-body :height="mescroll_height +'px'" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
		:up="upOption">

		<zui-flat>
			<zui-panel>
				<template v-slot:left>
					<view class="avatar_box"><zui-avatar :src="infodata.avatar" size="120rpx"></zui-avatar></view>
				</template>
				<template v-slot:col>
					<zui-col height="172rpx">
						<view class="name">{{ infodata.nickname }}</view>
						<view class="num">
							<!-- <u-icon :name="require('@/static/img/v.png')" size="28rpx" ></u-icon> -->
							<view class="text">团队{{ info.team_num }}人</view>
						</view>
					</zui-col>
				</template>
				<template v-slot:right>
					<zui-arrBtn padding="30rpx"><u-button v-if="UpgradeState == 1" type="warning" size="small" shape="circle" text="升级" @click="updata"></u-button></zui-arrBtn>
				</template>
			</zui-panel>
		</zui-flat>

		<u-gap height="30rpx"></u-gap>

		<zui-flat>
			<u-gap height="30rpx"></u-gap>
			<u-cell :border="false" @click="xz_go('invite')" isLink title="我的推广码" bgColor='#AA334F'></u-cell>
			<u-gap height="30rpx"></u-gap>
		</zui-flat>

		<u-gap height="30rpx"></u-gap>

		<zui-flat v-if="list.length>0">
			<view class="list">
				<view class="item" v-for="(item, index) in list" :key="index">
					<zui-line v-if="index != 0"></zui-line>
					<zui-panel>
						<template v-slot:left>
							<view class="avatar_box"><zui-avatar :src="item.avatar" size="120rpx"></zui-avatar></view>
						</template>
						<template v-slot:col>
							<zui-col height="172rpx">
								<view class="name">{{ item.nickname }}</view>
								<view class="num">{{ item.mobile }}</view>
							</zui-col>
						</template>
					</zui-panel>
				</view>
			</view>
		</zui-flat>
		<!-- <view class="" v-if="list.length === 0"><u-empty mode="coupon" text=" "></u-empty></view> -->
		
		</mescroll-body>
		
		
	<!-- 	<u-loadmore status="status" :icon-type="iconType" :load-text="loadText" /> -->
	</zui-box>
</template>

<script>
	import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
	export default {
		mixins: [MescrollMixin,uni.$u.mpMixin, uni.$u.mixin],
	data() {
		return {
			UpgradeState: 0, //是否可以升级1-是 0-否
			page: 1,
			infodata: {},
			info: {},
		
			list: [],
			// 下拉刷新的配置(可选, 绝大部分情况无需配置)
			downOption: {
				auto: false //是否在初始化后,自动执行downCallback; 默认true
			},
			upOption: {
				auto: false // 是否在初始化完毕之后自动执行上拉加载的回调; 默认true
			},
			mescroll_height:'',
			
		};
	},
	onLoad() {
		this.get_info();
		// this.getdata();
	},
	created() {
		let that = this;
		   uni.getSystemInfo({ 
			success(res) {
			console.log('一',res.windowHeight); //可使用窗口高度
			that.mescroll_height = res.windowHeight - that.$u.getPx(uni.$u.props.navbar.height) - that.$u.sys().statusBarHeight -80
			
			console.log('二',that.mescroll_height)
			}
		})
	},
	onShow() {
		this.$nextTick(()=>{
			this.mescroll.resetUpScroll();
		})
	},
	methods: {
		get_info() {
			uni.$u.http
				.get('/app/user/getUserInfo', {
					params: {},
					custom: {
						auth: true,
						toast: true,
						catch: true
					}
				})
				.then(res => {
					this.infodata = res;
				})
				.catch(err => {});
			uni.$u.http
				.get('/app/user/getUpgradeState', {
					params: {},
					custom: {
						auth: true,
						toast: true,
						catch: true
					}
				})
				.then(res => {
					this.UpgradeState = res.state;
				})
				.catch(err => {});
		},
		updata() {
			uni.$u.http
				.get('/app/user/doUpgrade', {
					params: {},
					custom: {
						auth: true,
						toast: true,
						catch: true
					}
				})
				.then(res => {
					this.UpgradeState = 0;
					uni.$u.toast('提交成功');
				})
				.catch(err => {});
		},
		
		//下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
		downCallback() {
			setTimeout(() => {
				this.mescroll.resetUpScroll();
			}, 1000);
		},
		/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
		 upCallback(page) {
			 
			uni.$u.http
				.get('/app/user/getInviteList', {
					params: {
						page: page.num,
					},
					custom: {
						auth: true,
						toast: false,
						catch: false,
					},
				})
				.then(res => {
					console.log('返回的数据', res);
					this.mescroll.endSuccess(res.list.length);
					//设置列表数据
					if (page.num == 1) this.list = []; //如果是第一页需手动制空列表
					this.list = this.list.concat(res.list); //追加新数据
		
				})
				.catch(res => {
					this.mescroll.endErr();
				});
		},
		
	
	},
	
};
</script>

<style lang="scss" scoped>
	
	/* //空数据 */
		/deep/.mescroll-empty {
			box-sizing: border-box;
			width: 100%;
			padding: 300rpx 50rpx;
			text-align: center;
		}
		
		
.name {
	color: #333;
}
.num {
	align-items: center;
	display: flex;
	color: #333;
	.text {
		margin-left: 16rpx;
		line-height: 1;
	}
}
.list {
	padding-bottom: 100rpx;
}
/deep/.u-cell__title-text {
	color: #fff !important;
	font-size: 28rpx;
}
/deep/.u-cell__left-icon-wrap {
	margin-right: 20rpx;
}
/deep/.u-cell--clickable {
	background: #232539;
}
/deep/.u-cell {
	background: rgb(238, 174, 79);
	border-radius: 20rpx;
}
/deep/.u-cell__value {
	color: #bfbfbf !important;
}
.u-cell__body {
	padding: 0;
}
</style>
